package com.xd.lib.animation;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.xd.lib.Const;
import com.xd.lib.R;
import com.xd.lib.tool.util.EffectUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/6/15.
 */
public class AnimActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_layout);

        int[] icons = {
                R.mipmap.ic_launcher,
                R.drawable.disc
        };
        String[][] funcNames = {
                {"闪烁文字", "变换文字颜色，以实现闪烁的效果"},
                {"盘片播放动画", "点击开始，拨杆转动到盘片上，盘片开始旋转，音乐播放"}
        };

        List<Map<String, Object>> data = new ArrayList<>();
        for (int i=0;i<funcNames.length;i++){
            Map<String, Object> map = new HashMap<>();
            map.put(Const.STRING_ICON, icons[i]);
            map.put(Const.STRING_TITLE, funcNames[i][Const.INDEX_LISTVIEW_TITLE]);
            map.put(Const.STRING_DESCRIPTION, funcNames[i][Const.INDEX_LISTVIEW_DESCRIPTION]);
            data.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(
                this,
                data,
                R.layout.listview_item,
                new String[]{Const.STRING_ICON, Const.STRING_TITLE, Const.STRING_DESCRIPTION},
                new int[]{R.id.listview_item_image, R.id.listview_item_txt_title, R.id.listview_item_txt_description}
        );

        final ListView listView = (ListView)findViewById(R.id.listview);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int index = listView.getCount() - position;
                Intent intent = null;
                switch (index){
                    case 2:
                        TextView textView = (TextView)AnimActivity.this.findViewById(R.id.listview_item_txt_title);
                        if (textView != null){
                            EffectUtil.sparkText(AnimActivity.this,
                                    textView,
                                    new int[]{Color.RED, Color.WHITE},
                                    10);
                        }
                        break;
                    case 1:
                        intent = new Intent(AnimActivity.this, DiscActivity.class);
                        break;
                }
                if (intent != null) {
                    AnimActivity.this.startActivity(intent);
                }
            }
        });
    }
}
